package com.controller;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.bean.User;
import com.service.UserService;

@SuppressWarnings("serial")
@WebServlet("/LoginoutServlet/*")
public class LoginoutServlet extends AncestorServlet
{
	
	private final UserService userService = UserService.getInstance();
	
	
	
	/**
	 * 登陆
	 */
	public String login(HttpServletRequest request, HttpSession session)
	{
		String account = request.getParameter("account");
		String password = request.getParameter("password");
		User user = userService.queryOneUser(account, password);
		if(user != null)
		{
			session.setAttribute("message", "登陆成功");
			session.setAttribute("loginer", user);
			return "r:/index.jsp";
		}
		session.setAttribute("message", "登陆失败：账号或密码错误");
		return "r:/user-login.jsp";
	}
	
	
	
	
	
	/**
	 * 退出
	 */
	public String logout(HttpSession session)
	{
		session.invalidate();
		return "r:/index.jsp";
	}
	
	
	
}